#pragma warning(disable : 4996)
#include"heap.h"
void CreatDate()
{
	FILE* p = fopen("date.txt", "w");
	if (p == NULL)
	{
		perror("fopen fail");
	}
	int x = 0;
	for (int i = 0; i < 1000; i++)
	{
		x = rand() % 1000;
		fprintf(p, "%d\n", x);
	}
	fclose(p);
}
void Topk(int k )
{
	int* arr = (int *)malloc(sizeof(int) * 50);
	FILE* p = fopen("date.txt", "r");
	int temp = 0;
	for (int i = 0; i < k; i++)
	{
		fscanf(p, "%d", arr+i);
	}
	for (int i = 1; i <k; i++)
	{
		AdjustUp(arr, i);
	}
	while (fscanf(p, "%d", &temp) != EOF)
	{
		if (temp > arr[0])
		{
			arr[0] = temp;
			AdjustDown(arr,0,k);
		}
	}
	


}
int main()
{
	Heap s1;
	InIt(&s1);
	HeapPush(&s1, 1);
	HeapPush(&s1, 10);
	HeapPush(&s1, 3);
	HeapPush(&s1, 78);
	HeapPush(&s1, 45);
	HeapPop(&s1);
	HeapPop(&s1);
	HeapPop(&s1);
	HeapPop(&s1);
	HeapPop(&s1);
	
	HeapDestory(&s1);
	srand((unsigned)time(NULL));
	//CreatDate();
	int arr[50] = { 0 };
	Topk(4);

	return 0;
}